package com.ics.top.batch.management.service;
import com.ics.top.domain.BatchUserManagementLogs;
import com.ics.top.exception.ServiceException;
import com.ics.top.repository.BatchUserManagementLogsRepository;
import com.ics.top.service.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * Created by Administrator on 2018/4/25.
 */
@Service
@Transactional("")
public class BatchUserManagementLogClient {
        private Logger log = LoggerFactory.getLogger(getClass());

        @Autowired
        private BatchUserManagementLogsRepository batchUserManagementLogsRepository;

        public BatchUserManagementLogs add(int num , String  managementIds , String parameters , String result){
            BatchUserManagementLogs batchLogs = new BatchUserManagementLogs();
            try {
                Date time = DateUtil.getDate();
                batchLogs.setManagementIds(managementIds);
                batchLogs.setParameters(parameters);
                batchLogs.setNum(num);
                batchLogs.setResult(result);
                batchLogs.setCreateTime(time);
                batchLogs.setUpdateTime(time);
                batchLogs  =  batchUserManagementLogsRepository.save(batchLogs);
                log.info("保存日志成功 BatchAssessLogs {}:",batchLogs);
                return batchLogs;
            }catch (ServiceException e){
                return  null;
            }

        }
        public void update(Long id,String result){
            BatchUserManagementLogs batchLogs =   batchUserManagementLogsRepository.findOne(id);
            if(batchLogs != null){
                Date time = DateUtil.getDate();
                batchLogs.setResult(result);
                batchLogs.setUpdateTime(time);
                batchUserManagementLogsRepository.save(batchLogs);
                log.info("修改日志成功 BatchLogs {}:",batchLogs);
            }else{
                log.info("修改日志失败 BatchLogs {}:",batchLogs);
            }
        }
}
